package com.liuwei.msmall.member.controller;

import com.liuwei.msmall.common.dto.SocialUserDTO;
import com.liuwei.msmall.common.utils.PageUtils;
import com.liuwei.msmall.common.utils.R;
import com.liuwei.msmall.member.entity.MemberEntity;
import com.liuwei.msmall.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 会员
 *
 * @author llww
 * @email 2456888577@qq.com
 * @date 2021-02-25 17:47:33
 */
@RestController
@RequestMapping("member/member")
public class MemberController {

    @Autowired
    private MemberService memberService;


    /**
     * 第三方登录
     */
    @PostMapping("/weibologin")
    public R weibologin(@RequestBody SocialUserDTO to){

        try {
            MemberEntity memberEntity= memberService.login(to);
            return R.ok().setData(memberEntity);
        }catch (Exception e){
            return R.error();
        }

    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
